<template>
	<view v-if="activityobj" class="page page-help"
		:style="{
			backgroundImage: 'url(' + imgPath + '/app/game_hotel/' + activityId + '/bg.png)',
			backgroundColor: activityobj.bjs
		}"
	>
		<!-- banner -->
		<image class="banner" mode="widthFix" :src="imgPath + '/app/game_hotel/' + activityId + '/banner.png'"></image>
		<!-- 头部 -->
		<view class="help_title box-shadow flex-column-between" :style="{height: isSelf ? '200rpx' : '250rpx'}">
			<view class="font-666666 font13">已获得助力次数</view>
			<view class="help_num">{{count}}</view>
			<view v-if="!isSelf" class="btns flex-row-between">
				<view class="btn btn1" @click="OnsetHelp">为ta助力</view>
				<view class="btn btn2" @click="Onjoin">我也要参加</view>
			</view>
		</view>
		<!-- 助力榜 -->
		<view class="help_list box-shadow">
			<view class="font15 font-b tc">助力榜</view>
			<!-- 列表 -->
			<view class="list_bos">
				<LoadMore ref="LoadMore" id="LoadMore" :token="true" :diffHeight="660" :initData="initData" @dataRefresh='dataRefresh' @infoRefresh='infoRefresh'>
					<view class="list_box flex-row-between" v-for="(item, index) in dataList" :key="index">
						<view class="flex-row-center">
							<image :src="item.user_info.avatar"></image>
							<text class="list_text ellipsis font14">{{item.user_info.name}}</text>
						</view>
						<view class="font13 font-969696">{{item.createtime}}</view>
					</view>
				</LoadMore>
			</view>
		</view>
	</view>
</template>

<script>
	import LoadMore from "@/components/j-loadMore/index.vue";
	export default {
		components: { LoadMore },
		data() {
			return {
				themeColor: '#03004c', // 主题色
				imgPath: this.$Config.http_static, // 图片头
				bgcolor: '#0c16cd', // 背景色
				
				activityId: '', // 活动id
				activityobj: null, // 活动详情
				activityType: '', // 活动类型:wheel-转盘, card集卡
				activityMode: '', // 活动点击来源:self-自己
				
				idInfo_origin: {}, // 原始的id信息
				idInfo: {}, // 登录后的id信息
				userInfo: {}, // 用户信息
				userType: 2, // 用户类型:1员工，2会员
				
				count: 0, // 次数
				isSelf: false, // 是否自己的助力榜
				
				//传参数据
				initData: {
				  url: 'help',
				  param: {
					activity_id: '',
					user_id: ''
				  }
				},
				dataList: [],
			}
		},
		onLoad: function (options) {
			let params = {}
			
			// 一个参数
			params = options;
			
			// 多个参数
			if(this.$Route.query.data){
				params = this.$base.OnWxoptions(this.$Route.query.data)
			}
			if(this.$Route.query.scene){
				params = this.$base.OnWxoptions(this.$Route.query.scene)
			}
			
			this.activityType = params.type
			this.activityMode = params.mode
			this.activityId = params.id
			this.initData.param.activity_id = params.id
			
			// 从缓存中拿取id信息
			this.idInfo_origin = uni.getStorageSync('idInfo_origin')
			this.idInfo = uni.getStorageSync('idInfo')
			
			// 获取用户信息
			this.$Http({
				url: 'user',
				token: true,
				load: true
			}).then(res => {
				// 赋值
				this.userInfo = res.data.user
				
				// 员工身份
				let type = this.userInfo.group
				if (type.indexOf('员工') >= 0) {
				  this.userType = 1
				} else if (type.indexOf('会员') >= 0) {
				  this.userType = 2
				}
				
				// 来源
				if (this.activityMode == 'self') {
					// 自己点击进来
					this.isSelf = true
					this.initData.param.user_id = this.userInfo.user_id
				} else {
					// 分享点击进来
					if (this.idInfo_origin.Fid == this.userInfo.user_id) {
						this.isSelf = true
					} else {
						this.isSelf = false
					}
					this.initData.param.user_id = this.idInfo_origin.Fid
				}
				this.$refs.LoadMore.oncutRefresh(this.initData);
				
			});
			
			// 活动详情
			this.$Http({
				url: 'getActivity',
				token: true,
				data: {
					activity_id: this.activityId
				},
			}).then(res => {
				if (res.code == 1) {
					this.activityobj = res.data
				}
			});
		},
		methods: {
			// LoadMore返回列表数据
			dataRefresh(e){
				this.dataList = e
			},
			// LoadMore返回信息
			infoRefresh(e){
				this.count = e.count
			},
			// 为他助力
			OnsetHelp() {
				this.$Http({
					url: 'setHelp',
					token: true,
					load: true,
					data: {
						activity_id: this.activityId,
						helper_id: this.idInfo_origin.Fid
					},
				}).then(res => {
					if (res.code == 1) {
						uni.showToast({ title: '助力成功' })
						this.$refs.LoadMore.oncutRefresh(this.initData)
					} else {
						uni.showToast({ title: res.msg, icon: 'none' })
					}
				});
			},
			// 参加活动
			Onjoin () {
				// 更新缓存中的id信息为自己的
				let ids = {};
				if (this.userType == 1) {
				  ids.Pid = this.userInfo.user_id
				} else {
				  ids.Pid = this.userInfo.parent_id
				}
				
				ids.Fid = this.userInfo.user_id;
				
				let $C = this.idInfo.Cid;
				if ($C) {
					ids.Cid = $C
				}
				
				uni.setStorage({key: 'idInfo', data: ids })
				
				// 跳转到对应的活动页面
				switch (this.activityType) {
					case 'wheel':
						uni.reLaunch({
							url: '/pages/activity/wheel/index?id=' + this.activityId
						})
						break
					case 'card':
						uni.reLaunch({
							url: '/pages/activity/card/index?data=id.' + this.activityId
						})
						break
					default:
						uni.switchTab({
							url: '/pages/home/index'
						})
						break
				}
			}
		}
	}
</script>

<style lang="less">
	@import url("style.less");
</style>
